package com.cory.boot.utils;

import org.springframework.core.env.Environment;
import com.cory.boot.domain.bean.Principal;
import com.cory.boot.sys.service.SysService;
import com.cory.utils.lang.StringUtils;

/**
 * @author xiongcong
 * @date 2022-01-10
 */
public class SysUtils {

    public static Principal getPrincipal() {
        SysService sysService = SpringUtils.getBean(SysService.class);
        if (sysService != null) {
           return sysService.getPrincipal();
        }
        return null;
    }
    
    public static Integer getLoginUserId() {
        Principal principal = SysUtils.getPrincipal();
        if (principal != null) {
            return principal.getUserId();
        }
        return null;
    }

    public static Integer getLoginTenantId() {
        Principal principal = SysUtils.getPrincipal();
        if (principal != null) {
            return principal.getTenantId();
        }
        return null;
    }

    public static String getSystem() {
        SysService sysService = SpringUtils.getBean(SysService.class);
        if (sysService != null) {
            return sysService.getSystem();
        }
        return null;
    }

    public static String getEntName() {
        String entName = SpringUtils.getBean(Environment.class).getProperty("admin.ent-name");
        return StringUtils.defaultIfBlank(entName, "企业");
    }
}
